package DAO;

import java.util.List;

import hbt.HibernateUtil;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import Entidades.*;

public class SucursalDAO {
	private static SucursalDAO instancia = null;
	private static SessionFactory sf = null;
	
	public static SucursalDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new SucursalDAO();
		} 
		return instancia;
	}
	
	@SuppressWarnings("unchecked")
	public List<Sucursal> obtenerListaSucursales() throws Exception {
		try {
			Session session = sf.openSession();
			Query q = session.createQuery("from Sucursal ");
			List<Sucursal> listaSucursal = new ArrayList<Sucursal>(q.list());
			session.close();
			return listaSucursal;
		} catch (Exception e) {
			throw e;
		}
	}
	
}
